package spring.angularjs.dao;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import spring.angularjs.domain.Account;

@Repository
public class AccountDAOImpl implements AccountDAO {
	
	@Autowired
	private SessionFactory sessionFactory;

	@Override
	public List<Account> getListAccount() {
		return sessionFactory.getCurrentSession().createCriteria(Account.class).list();
	}

	@Override
	public Account getAccountById(String id) {
		return (Account) sessionFactory.getCurrentSession().get(Account.class, id);
	}

	@Override
	public void updateAccount(Account ac) {
		sessionFactory.getCurrentSession().update(ac);
	}

	@Override
	public List<Account> getListAccountOfCustomer(String id) {
		Query query = sessionFactory.getCurrentSession().createQuery("select a from Account a where a.customer.idcustomer = :m");
		query.setParameter("m", id);
		return query.list();
	}

}
